
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.io.lammps.data &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.lammps.data</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.io.lammps.data</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module implements a core class LammpsData for generating/parsing</span>
<span class="sd">LAMMPS data file, and other bridging classes to build LammpsData from</span>
<span class="sd">molecules. This module also implements a subclass CombinedData for</span>
<span class="sd">merging LammpsData object.</span>

<span class="sd">Only point particle styles are supported for now (atom_style in angle,</span>
<span class="sd">atomic, bond, charge, full and molecular only). See the pages below for</span>
<span class="sd">more info.</span>

<span class="sd">    http://lammps.sandia.gov/doc/atom_style.html</span>
<span class="sd">    http://lammps.sandia.gov/doc/read_data.html</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">OrderedDict</span>
<span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="n">StringIO</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">warnings</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span>
<span class="kn">from</span> <span class="nn">monty.dev</span> <span class="kn">import</span> <span class="n">deprecated</span>
<span class="kn">from</span> <span class="nn">monty.serialization</span> <span class="kn">import</span> <span class="n">loadfn</span>
<span class="kn">from</span> <span class="nn">ruamel.yaml</span> <span class="kn">import</span> <span class="n">YAML</span>

<span class="kn">from</span> <span class="nn">pymatgen.util.io_utils</span> <span class="kn">import</span> <span class="n">clean_lines</span>
<span class="kn">from</span> <span class="nn">pymatgen</span> <span class="kn">import</span> <span class="n">Molecule</span><span class="p">,</span> <span class="n">Element</span><span class="p">,</span> <span class="n">Lattice</span><span class="p">,</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">SymmOp</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Kiran Mathew, Zhi Deng, Tingzheng Hou&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2018, The Materials Virtual Lab&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Zhi Deng&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;z4deng@eng.ucsd.edu&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Aug 1, 2018&quot;</span>

<span class="n">MODULE_DIR</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span><span class="o">.</span><span class="n">parent</span>

<span class="n">SECTION_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;atom&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">,</span> <span class="s2">&quot;Velocities&quot;</span><span class="p">,</span> <span class="s2">&quot;Masses&quot;</span><span class="p">,</span>
                             <span class="s2">&quot;Ellipsoids&quot;</span><span class="p">,</span> <span class="s2">&quot;Lines&quot;</span><span class="p">,</span> <span class="s2">&quot;Triangles&quot;</span><span class="p">,</span> <span class="s2">&quot;Bodies&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;topology&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Bonds&quot;</span><span class="p">,</span> <span class="s2">&quot;Angles&quot;</span><span class="p">,</span> <span class="s2">&quot;Dihedrals&quot;</span><span class="p">,</span> <span class="s2">&quot;Impropers&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;ff&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;Pair Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;Bond Coeffs&quot;</span><span class="p">,</span>
                           <span class="s2">&quot;Angle Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;Dihedral Coeffs&quot;</span><span class="p">,</span>
                           <span class="s2">&quot;Improper Coeffs&quot;</span><span class="p">],</span>
                    <span class="s2">&quot;class2&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;BondBond Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;BondAngle Coeffs&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;MiddleBondTorsion Coeffs&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;EndBondTorsion Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;AngleTorsion Coeffs&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;AngleAngleTorsion Coeffs&quot;</span><span class="p">,</span>
                               <span class="s2">&quot;BondBond13 Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;AngleAngle Coeffs&quot;</span><span class="p">]}</span>

<span class="n">CLASS2_KEYWORDS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Angle Coeffs&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;BondBond Coeffs&quot;</span><span class="p">,</span> <span class="s2">&quot;BondAngle Coeffs&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Dihedral Coeffs&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;MiddleBondTorsion Coeffs&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;EndBondTorsion Coeffs&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;AngleTorsion Coeffs&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;AngleAngleTorsion Coeffs&quot;</span><span class="p">,</span>
                                       <span class="s2">&quot;BondBond13 Coeffs&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Improper Coeffs&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;AngleAngle Coeffs&quot;</span><span class="p">]}</span>

<span class="n">SECTION_HEADERS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Masses&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;mass&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Velocities&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;vx&quot;</span><span class="p">,</span> <span class="s2">&quot;vy&quot;</span><span class="p">,</span> <span class="s2">&quot;vz&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Bonds&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;atom1&quot;</span><span class="p">,</span> <span class="s2">&quot;atom2&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Angles&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;atom1&quot;</span><span class="p">,</span> <span class="s2">&quot;atom2&quot;</span><span class="p">,</span> <span class="s2">&quot;atom3&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Dihedrals&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;atom1&quot;</span><span class="p">,</span> <span class="s2">&quot;atom2&quot;</span><span class="p">,</span> <span class="s2">&quot;atom3&quot;</span><span class="p">,</span> <span class="s2">&quot;atom4&quot;</span><span class="p">],</span>
                   <span class="s2">&quot;Impropers&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;atom1&quot;</span><span class="p">,</span> <span class="s2">&quot;atom2&quot;</span><span class="p">,</span> <span class="s2">&quot;atom3&quot;</span><span class="p">,</span> <span class="s2">&quot;atom4&quot;</span><span class="p">]}</span>

<span class="n">ATOMS_HEADERS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;angle&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">],</span>
                 <span class="s2">&quot;atomic&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">],</span>
                 <span class="s2">&quot;bond&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">],</span>
                 <span class="s2">&quot;charge&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;q&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">],</span>
                 <span class="s2">&quot;full&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;q&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">],</span>
                 <span class="s2">&quot;molecular&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">]}</span>


<div class="viewcode-block" id="LammpsBox"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsBox">[docs]</a><span class="k">class</span> <span class="nc">LammpsBox</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for representing a simulation box in LAMMPS settings.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bounds</span><span class="p">,</span> <span class="n">tilt</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        Args:</span>
<span class="sd">            bounds: A (3, 2) array/list of floats setting the</span>
<span class="sd">                boundaries of simulation box.</span>
<span class="sd">            tilt: A (3,) array/list of floats setting the tilt of</span>
<span class="sd">                simulation box. Default to None, i.e., use an</span>
<span class="sd">                orthogonal box.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">bounds_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bounds</span><span class="p">)</span>
        <span class="k">assert</span> <span class="n">bounds_arr</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> \
            <span class="s2">&quot;Expecting a (3, 2) array for bounds,&quot;</span> \
            <span class="s2">&quot; got </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">bounds_arr</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bounds</span> <span class="o">=</span> <span class="n">bounds_arr</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="n">matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">diag</span><span class="p">(</span><span class="n">bounds_arr</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">bounds_arr</span><span class="p">[:,</span> <span class="mi">0</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">tilt</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">tilt</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">tilt_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">tilt</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">tilt_arr</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="mi">3</span><span class="p">,),</span> \
                <span class="s2">&quot;Expecting a (3,) array for box_tilt,&quot;</span> \
                <span class="s2">&quot; got </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">tilt_arr</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">tilt</span> <span class="o">=</span> <span class="n">tilt_arr</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="n">matrix</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">tilt_arr</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">matrix</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">tilt_arr</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">matrix</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">tilt_arr</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_matrix</span> <span class="o">=</span> <span class="n">matrix</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">volume</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Volume of simulation box.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_matrix</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">cross</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>

<div class="viewcode-block" id="LammpsBox.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsBox.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">significant_figures</span><span class="o">=</span><span class="mi">6</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the string representation of simulation box in LAMMPS</span>
<span class="sd">        data file format.</span>

<span class="sd">        Args:</span>
<span class="sd">            significant_figures (int): No. of significant figures to</span>
<span class="sd">                output for box settings. Default to 6.</span>

<span class="sd">        Returns:</span>
<span class="sd">            String representation</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">ph</span> <span class="o">=</span> <span class="s2">&quot;{:.</span><span class="si">%d</span><span class="s2">f}&quot;</span> <span class="o">%</span> <span class="n">significant_figures</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">bound</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bounds</span><span class="p">,</span> <span class="s2">&quot;xyz&quot;</span><span class="p">):</span>
            <span class="n">fillers</span> <span class="o">=</span> <span class="n">bound</span> <span class="o">+</span> <span class="p">[</span><span class="n">d</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span>
            <span class="n">bound_format</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">ph</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot; </span><span class="si">{}</span><span class="s2">lo </span><span class="si">{}</span><span class="s2">hi&quot;</span><span class="p">])</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">bound_format</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="n">fillers</span><span class="p">))</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">tilt</span><span class="p">:</span>
            <span class="n">tilt_format</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">ph</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot; xy xz yz&quot;</span><span class="p">])</span>
            <span class="n">lines</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tilt_format</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">tilt</span><span class="p">))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsBox.get_box_shift"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsBox.get_box_shift">[docs]</a>    <span class="k">def</span> <span class="nf">get_box_shift</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calculates the coordinate shift due to PBC.</span>

<span class="sd">        Args:</span>
<span class="sd">            i: A (n, 3) integer array containing the labels for box</span>
<span class="sd">            images of n entries.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Coorindate shift array with the same shape of i</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">inner</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_matrix</span><span class="o">.</span><span class="n">T</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsBox.to_lattice"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsBox.to_lattice">[docs]</a>    <span class="k">def</span> <span class="nf">to_lattice</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Converts the simulation box to a more powerful Lattice backend.</span>
<span class="sd">        Note that Lattice is always periodic in 3D space while a</span>
<span class="sd">        simulation box is not necessarily periodic in all dimensions.</span>

<span class="sd">        Returns:</span>
<span class="sd">            Lattice</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">Lattice</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_matrix</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="lattice_2_lmpbox"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.lattice_2_lmpbox">[docs]</a><span class="k">def</span> <span class="nf">lattice_2_lmpbox</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="n">origin</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Converts a lattice object to LammpsBox, and calculates the symmetry</span>
<span class="sd">    operation used.</span>

<span class="sd">    Args:</span>
<span class="sd">        lattice (Lattice): Input lattice.</span>
<span class="sd">        origin: A (3,) array/list of floats setting lower bounds of</span>
<span class="sd">            simulation box. Default to (0, 0, 0).</span>

<span class="sd">    Returns:</span>
<span class="sd">        LammpsBox, SymmOp</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">abc</span>
    <span class="n">xlo</span><span class="p">,</span> <span class="n">ylo</span><span class="p">,</span> <span class="n">zlo</span> <span class="o">=</span> <span class="n">origin</span>
    <span class="n">xhi</span> <span class="o">=</span> <span class="n">a</span> <span class="o">+</span> <span class="n">xlo</span>
    <span class="n">m</span> <span class="o">=</span> <span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span>
    <span class="n">xy</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">a</span><span class="p">)</span>
    <span class="n">yhi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">b</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">xy</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">ylo</span>
    <span class="n">xz</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">a</span><span class="p">)</span>
    <span class="n">yz</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">-</span> <span class="n">xy</span> <span class="o">*</span> <span class="n">xz</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">yhi</span> <span class="o">-</span> <span class="n">ylo</span><span class="p">)</span>
    <span class="n">zhi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">c</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">xz</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">yz</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="n">zlo</span>
    <span class="n">tilt</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="n">lattice</span><span class="o">.</span><span class="n">is_orthogonal</span> <span class="k">else</span> <span class="p">[</span><span class="n">xy</span><span class="p">,</span> <span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">]</span>
    <span class="n">rot_matrix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">([[</span><span class="n">xhi</span> <span class="o">-</span> <span class="n">xlo</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                                  <span class="p">[</span><span class="n">xy</span><span class="p">,</span> <span class="n">yhi</span> <span class="o">-</span> <span class="n">ylo</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span>
                                  <span class="p">[</span><span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">zhi</span> <span class="o">-</span> <span class="n">zlo</span><span class="p">]],</span> <span class="n">m</span><span class="p">)</span>
    <span class="n">bounds</span> <span class="o">=</span> <span class="p">[[</span><span class="n">xlo</span><span class="p">,</span> <span class="n">xhi</span><span class="p">],</span> <span class="p">[</span><span class="n">ylo</span><span class="p">,</span> <span class="n">yhi</span><span class="p">],</span> <span class="p">[</span><span class="n">zlo</span><span class="p">,</span> <span class="n">zhi</span><span class="p">]]</span>
    <span class="n">symmop</span> <span class="o">=</span> <span class="n">SymmOp</span><span class="o">.</span><span class="n">from_rotation_and_translation</span><span class="p">(</span><span class="n">rot_matrix</span><span class="p">,</span> <span class="n">origin</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">LammpsBox</span><span class="p">(</span><span class="n">bounds</span><span class="p">,</span> <span class="n">tilt</span><span class="p">),</span> <span class="n">symmop</span></div>


<div class="viewcode-block" id="LammpsData"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData">[docs]</a><span class="k">class</span> <span class="nc">LammpsData</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for representing the data in a LAMMPS data file.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">box</span><span class="p">,</span> <span class="n">masses</span><span class="p">,</span> <span class="n">atoms</span><span class="p">,</span> <span class="n">velocities</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">force_field</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">topology</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;full&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        This is a low level constructor designed to work with parsed</span>
<span class="sd">        data or other bridging objects (ForceField and Topology). Not</span>
<span class="sd">        recommended to use directly.</span>

<span class="sd">        Args:</span>
<span class="sd">            box (LammpsBox): Simulation box.</span>
<span class="sd">            masses (pandas.DataFrame): DataFrame with one column</span>
<span class="sd">                [&quot;mass&quot;] for Masses section.</span>
<span class="sd">            atoms (pandas.DataFrame): DataFrame with multiple columns</span>
<span class="sd">                for Atoms section. Column names vary with atom_style.</span>
<span class="sd">            velocities (pandas.DataFrame): DataFrame with three columns</span>
<span class="sd">                [&quot;vx&quot;, &quot;vy&quot;, &quot;vz&quot;] for Velocities section. Optional</span>
<span class="sd">                with default to None. If not None, its index should be</span>
<span class="sd">                consistent with atoms.</span>
<span class="sd">            force_field (dict): Data for force field sections. Optional</span>
<span class="sd">                with default to None. Only keywords in force field and</span>
<span class="sd">                class 2 force field are valid keys, and each value is a</span>
<span class="sd">                DataFrame.</span>
<span class="sd">            topology (dict): Data for topology sections. Optional with</span>
<span class="sd">                default to None. Only keywords in topology are valid</span>
<span class="sd">                keys, and each value is a DataFrame.</span>
<span class="sd">            atom_style (str): Output atom_style. Default to &quot;full&quot;.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="n">velocities</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">velocities</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">atoms</span><span class="p">),</span> \
                <span class="s2">&quot;Inconsistency found between atoms and velocities&quot;</span>

        <span class="k">if</span> <span class="n">force_field</span><span class="p">:</span>
            <span class="n">all_ff_kws</span> <span class="o">=</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;class2&quot;</span><span class="p">]</span>
            <span class="n">force_field</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">force_field</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                           <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">all_ff_kws</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">topology</span><span class="p">:</span>
            <span class="n">topology</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topology</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                        <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="n">box</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">masses</span> <span class="o">=</span> <span class="n">masses</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span> <span class="o">=</span> <span class="n">atoms</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="o">=</span> <span class="n">velocities</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span> <span class="o">=</span> <span class="n">force_field</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">topology</span> <span class="o">=</span> <span class="n">topology</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atom_style</span> <span class="o">=</span> <span class="n">atom_style</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Exports a periodic structure object representing the simulation</span>
<span class="sd">        box.</span>

<span class="sd">        Return:</span>
<span class="sd">            Structure</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">masses</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">masses</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">if</span> <span class="s2">&quot;nx&quot;</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="n">atoms</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s2">&quot;nx&quot;</span><span class="p">,</span> <span class="s2">&quot;ny&quot;</span><span class="p">,</span> <span class="s2">&quot;nz&quot;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="n">ld_copy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="p">,</span> <span class="n">masses</span><span class="p">,</span> <span class="n">atoms</span><span class="p">)</span>
        <span class="n">topologies</span> <span class="o">=</span> <span class="n">ld_copy</span><span class="o">.</span><span class="n">disassemble</span><span class="p">()[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">molecule</span> <span class="o">=</span> <span class="n">topologies</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">sites</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="n">molecule</span><span class="o">.</span><span class="n">cart_coords</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="o">.</span><span class="n">bounds</span><span class="p">)[:,</span> <span class="mi">0</span><span class="p">]</span>
        <span class="n">species</span> <span class="o">=</span> <span class="n">molecule</span><span class="o">.</span><span class="n">species</span>
        <span class="n">latt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="o">.</span><span class="n">to_lattice</span><span class="p">()</span>
        <span class="n">site_properties</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">if</span> <span class="s2">&quot;q&quot;</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">:</span>
            <span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;charge&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;q&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="o">.</span><span class="n">values</span>
        <span class="k">return</span> <span class="n">Structure</span><span class="p">(</span><span class="n">latt</span><span class="p">,</span> <span class="n">species</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                         <span class="n">site_properties</span><span class="o">=</span><span class="n">site_properties</span><span class="p">)</span>

<div class="viewcode-block" id="LammpsData.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">velocity</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mi">4</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the string representation of LammpsData, essentially</span>
<span class="sd">        the string to be written to a file. Support hybrid style</span>
<span class="sd">        coeffs read and write.</span>

<span class="sd">        Args:</span>
<span class="sd">            distance (int): No. of significant figures to output for</span>
<span class="sd">                box settings (bounds and tilt) and atomic coordinates.</span>
<span class="sd">                Default to 6.</span>
<span class="sd">            velocity (int): No. of significant figures to output for</span>
<span class="sd">                velocities. Default to 8.</span>
<span class="sd">            charge (int): No. of significant figures to output for</span>
<span class="sd">                charges. Default to 3.</span>

<span class="sd">        Returns:</span>
<span class="sd">            String representation</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">file_template</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;Generated by pymatgen.io.lammps.data.LammpsData</span>

<span class="si">{stats}</span><span class="s2"></span>

<span class="si">{box}</span><span class="s2"></span>

<span class="si">{body}</span><span class="s2"></span>
<span class="s2">&quot;&quot;&quot;</span>
        <span class="n">box</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="n">distance</span><span class="p">)</span>

        <span class="n">body_dict</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="n">body_dict</span><span class="p">[</span><span class="s2">&quot;Masses&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">masses</span>
        <span class="n">types</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="n">types</span><span class="p">[</span><span class="s2">&quot;atom&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">masses</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">:</span>
            <span class="n">all_ff_kws</span> <span class="o">=</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;class2&quot;</span><span class="p">]</span>
            <span class="n">ff_kws</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">all_ff_kws</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">ff_kws</span><span class="p">:</span>
                <span class="n">body_dict</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">][</span><span class="mi">2</span><span class="p">:]:</span>
                    <span class="n">types</span><span class="p">[</span><span class="n">kw</span><span class="o">.</span><span class="n">lower</span><span class="p">()[:</span><span class="o">-</span><span class="mi">7</span><span class="p">]]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">])</span>

        <span class="n">body_dict</span><span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span>
        <span class="n">counts</span> <span class="o">=</span> <span class="n">OrderedDict</span><span class="p">()</span>
        <span class="n">counts</span><span class="p">[</span><span class="s2">&quot;atoms&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">body_dict</span><span class="p">[</span><span class="s2">&quot;Velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">kw</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
                    <span class="n">body_dict</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span>
                    <span class="n">counts</span><span class="p">[</span><span class="n">kw</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">])</span>

        <span class="n">all_stats</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">counts</span><span class="o">.</span><span class="n">values</span><span class="p">())</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">types</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
        <span class="n">stats_template</span> <span class="o">=</span> <span class="s2">&quot;{:&gt;</span><span class="si">%d</span><span class="s2">}  </span><span class="si">{}</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="nb">max</span><span class="p">(</span><span class="n">all_stats</span><span class="p">)))</span>
        <span class="n">count_lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">stats_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">counts</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span>
        <span class="n">type_lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">stats_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">k</span> <span class="o">+</span> <span class="s2">&quot; types&quot;</span><span class="p">)</span>
                      <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">types</span><span class="o">.</span><span class="n">items</span><span class="p">()]</span>
        <span class="n">stats</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">count_lines</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">type_lines</span><span class="p">)</span>

        <span class="k">def</span> <span class="nf">map_coords</span><span class="p">(</span><span class="n">q</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;{:.</span><span class="si">%d</span><span class="s2">f}&quot;</span> <span class="o">%</span> <span class="n">distance</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>

        <span class="k">def</span> <span class="nf">map_velos</span><span class="p">(</span><span class="n">q</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;{:.</span><span class="si">%d</span><span class="s2">f}&quot;</span> <span class="o">%</span> <span class="n">velocity</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>

        <span class="k">def</span> <span class="nf">map_charges</span><span class="p">(</span><span class="n">q</span><span class="p">):</span>
            <span class="k">return</span> <span class="p">(</span><span class="s2">&quot;{:.</span><span class="si">%d</span><span class="s2">f}&quot;</span> <span class="o">%</span> <span class="n">charge</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>
        <span class="n">float_format</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:.9f}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
        <span class="n">float_format_2</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:.1f}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
        <span class="n">int_format</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:.0f}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span>
        <span class="n">default_formatters</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;x&quot;</span><span class="p">:</span> <span class="n">map_coords</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">:</span> <span class="n">map_coords</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">:</span> <span class="n">map_coords</span><span class="p">,</span>
                              <span class="s2">&quot;vx&quot;</span><span class="p">:</span> <span class="n">map_velos</span><span class="p">,</span> <span class="s2">&quot;vy&quot;</span><span class="p">:</span> <span class="n">map_velos</span><span class="p">,</span> <span class="s2">&quot;vz&quot;</span><span class="p">:</span> <span class="n">map_velos</span><span class="p">,</span>
                              <span class="s2">&quot;q&quot;</span><span class="p">:</span> <span class="n">map_charges</span><span class="p">}</span>
        <span class="n">coeffsdatatype</span> <span class="o">=</span> <span class="n">loadfn</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">MODULE_DIR</span> <span class="o">/</span> <span class="s2">&quot;CoeffsDataType.yaml&quot;</span><span class="p">))</span>
        <span class="n">coeffs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">style</span><span class="p">,</span> <span class="n">types</span> <span class="ow">in</span> <span class="n">coeffsdatatype</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">coeffs</span><span class="p">[</span><span class="n">style</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="nb">type</span><span class="p">,</span> <span class="n">formatter</span> <span class="ow">in</span> <span class="n">types</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">coeffs</span><span class="p">[</span><span class="n">style</span><span class="p">][</span><span class="nb">type</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">coeff</span><span class="p">,</span> <span class="n">datatype</span> <span class="ow">in</span> <span class="n">formatter</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">datatype</span> <span class="o">==</span> <span class="s1">&#39;int_format&#39;</span><span class="p">:</span>
                        <span class="n">coeffs</span><span class="p">[</span><span class="n">style</span><span class="p">][</span><span class="nb">type</span><span class="p">][</span><span class="n">coeff</span><span class="p">]</span> <span class="o">=</span> <span class="n">int_format</span>
                    <span class="k">elif</span> <span class="n">datatype</span> <span class="o">==</span> <span class="s1">&#39;float_format_2&#39;</span><span class="p">:</span>
                        <span class="n">coeffs</span><span class="p">[</span><span class="n">style</span><span class="p">][</span><span class="nb">type</span><span class="p">][</span><span class="n">coeff</span><span class="p">]</span> <span class="o">=</span> <span class="n">float_format_2</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">coeffs</span><span class="p">[</span><span class="n">style</span><span class="p">][</span><span class="nb">type</span><span class="p">][</span><span class="n">coeff</span><span class="p">]</span> <span class="o">=</span> <span class="n">float_format</span>

        <span class="n">section_template</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{kw}</span><span class="se">\n\n</span><span class="si">{df}</span><span class="se">\n</span><span class="s2">&quot;</span>
        <span class="n">parts</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">body_dict</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">index</span> <span class="o">=</span> <span class="kc">True</span> <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span> <span class="k">else</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;Bond Coeffs&#39;</span><span class="p">,</span> <span class="s1">&#39;Angle Coeffs&#39;</span><span class="p">,</span> <span class="s1">&#39;Dihedral Coeffs&#39;</span><span class="p">,</span> <span class="s1">&#39;Improper Coeffs&#39;</span><span class="p">]:</span>
                <span class="n">listofdf</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array_split</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">index</span><span class="p">))</span>
                <span class="n">df_string</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">listofdf</span><span class="p">):</span>
                    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;coeff1&#39;</span><span class="p">],</span> <span class="nb">str</span><span class="p">):</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="n">formatters</span> <span class="o">=</span> <span class="p">{</span><span class="o">**</span><span class="n">default_formatters</span><span class="p">,</span> <span class="o">**</span><span class="n">coeffs</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">df</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;coeff1&#39;</span><span class="p">]]}</span>
                        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                            <span class="n">formatters</span> <span class="o">=</span> <span class="n">default_formatters</span>
                        <span class="n">line_string</span> <span class="o">=</span> \
                            <span class="n">df</span><span class="o">.</span><span class="n">to_string</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">formatters</span><span class="o">=</span><span class="n">formatters</span><span class="p">,</span>
                                         <span class="n">index_names</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">,</span> <span class="n">na_rep</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">line_string</span> <span class="o">=</span> \
                            <span class="n">v</span><span class="o">.</span><span class="n">to_string</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">formatters</span><span class="o">=</span><span class="n">default_formatters</span><span class="p">,</span>
                                        <span class="n">index_names</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">,</span>
                                        <span class="n">na_rep</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()[</span><span class="n">i</span><span class="p">]</span>
                    <span class="n">df_string</span> <span class="o">+=</span> <span class="n">line_string</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;nan&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">df_string</span> <span class="o">=</span> <span class="n">v</span><span class="o">.</span><span class="n">to_string</span><span class="p">(</span><span class="n">header</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">formatters</span><span class="o">=</span><span class="n">default_formatters</span><span class="p">,</span>
                                        <span class="n">index_names</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">,</span> <span class="n">na_rep</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
            <span class="n">parts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">section_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">kw</span><span class="o">=</span><span class="n">k</span><span class="p">,</span> <span class="n">df</span><span class="o">=</span><span class="n">df_string</span><span class="p">))</span>
        <span class="n">body</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parts</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">file_template</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">stats</span><span class="o">=</span><span class="n">stats</span><span class="p">,</span> <span class="n">box</span><span class="o">=</span><span class="n">box</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsData.write_file"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.write_file">[docs]</a>    <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">distance</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">velocity</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mi">4</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes LammpsData to file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename.</span>
<span class="sd">            distance (int): No. of significant figures to output for</span>
<span class="sd">                box settings (bounds and tilt) and atomic coordinates.</span>
<span class="sd">                Default to 6.</span>
<span class="sd">            velocity (int): No. of significant figures to output for</span>
<span class="sd">                velocities. Default to 8.</span>
<span class="sd">            charge (int): No. of significant figures to output for</span>
<span class="sd">                charges. Default to 3.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="n">distance</span><span class="o">=</span><span class="n">distance</span><span class="p">,</span> <span class="n">velocity</span><span class="o">=</span><span class="n">velocity</span><span class="p">,</span>
                                    <span class="n">charge</span><span class="o">=</span><span class="n">charge</span><span class="p">))</span></div>

<div class="viewcode-block" id="LammpsData.disassemble"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.disassemble">[docs]</a>    <span class="k">def</span> <span class="nf">disassemble</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">atom_labels</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">guess_element</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">ff_label</span><span class="o">=</span><span class="s2">&quot;ff_map&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Breaks down LammpsData to building blocks</span>
<span class="sd">        (LammpsBox, ForceField and a series of Topology).</span>
<span class="sd">        RESTRICTIONS APPLIED:</span>

<span class="sd">        1. No complex force field defined not just on atom</span>
<span class="sd">            types, where the same type or equivalent types of topology</span>
<span class="sd">            may have more than one set of coefficients.</span>
<span class="sd">        2. No intermolecular topologies (with atoms from different</span>
<span class="sd">            molecule-ID) since a Topology object includes data for ONE</span>
<span class="sd">            molecule or structure only.</span>

<span class="sd">        Args:</span>
<span class="sd">            atom_labels ([str]): List of strings (must be different</span>
<span class="sd">                from one another) for labelling each atom type found in</span>
<span class="sd">                Masses section. Default to None, where the labels are</span>
<span class="sd">                automaticaly added based on either element guess or</span>
<span class="sd">                dummy specie assignment.</span>
<span class="sd">            guess_element (bool): Whether to guess the element based on</span>
<span class="sd">                its atomic mass. Default to True, otherwise dummy</span>
<span class="sd">                species &quot;Qa&quot;, &quot;Qb&quot;, ... will be assigned to various</span>
<span class="sd">                atom types. The guessed or assigned elements will be</span>
<span class="sd">                reflected on atom labels if atom_labels is None, as</span>
<span class="sd">                well as on the species of molecule in each Topology.</span>
<span class="sd">            ff_label (str): Site property key for labeling atoms of</span>
<span class="sd">                different types. Default to &quot;ff_map&quot;.</span>

<span class="sd">        Returns:</span>
<span class="sd">            LammpsBox, ForceField, [Topology]</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">atoms_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">if</span> <span class="s2">&quot;nx&quot;</span> <span class="ow">in</span> <span class="n">atoms_df</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
            <span class="n">atoms_df</span><span class="p">[[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">]]</span> <span class="o">+=</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="o">.</span><span class="n">get_box_shift</span><span class="p">(</span><span class="n">atoms_df</span><span class="p">[[</span><span class="s2">&quot;nx&quot;</span><span class="p">,</span> <span class="s2">&quot;ny&quot;</span><span class="p">,</span> <span class="s2">&quot;nz&quot;</span><span class="p">]]</span><span class="o">.</span><span class="n">values</span><span class="p">)</span>
        <span class="n">atoms_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">atoms_df</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="n">mids</span> <span class="o">=</span> <span class="n">atoms_df</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">mids</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">unique_mids</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">data_by_mols</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;Atoms&quot;</span><span class="p">:</span> <span class="n">atoms_df</span><span class="p">}}</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">unique_mids</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">mids</span><span class="p">)</span>
            <span class="n">data_by_mols</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">unique_mids</span><span class="p">:</span>
                <span class="n">df</span> <span class="o">=</span> <span class="n">atoms_df</span><span class="p">[</span><span class="n">atoms_df</span><span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">k</span><span class="p">]</span>
                <span class="n">data_by_mols</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Atoms&quot;</span><span class="p">:</span> <span class="n">df</span><span class="p">}</span>

        <span class="n">masses</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">masses</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">masses</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">atom_labels</span>
        <span class="n">unique_masses</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">masses</span><span class="p">[</span><span class="s2">&quot;mass&quot;</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">guess_element</span><span class="p">:</span>
            <span class="n">ref_masses</span> <span class="o">=</span> <span class="p">[</span><span class="n">el</span><span class="o">.</span><span class="n">atomic_mass</span><span class="o">.</span><span class="n">real</span> <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">Element</span><span class="p">]</span>
            <span class="n">diff</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">ref_masses</span><span class="p">)</span> <span class="o">-</span> <span class="n">unique_masses</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">])</span>
            <span class="n">atomic_numbers</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">argmin</span><span class="p">(</span><span class="n">diff</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="n">Element</span><span class="o">.</span><span class="n">from_Z</span><span class="p">(</span><span class="n">an</span><span class="p">)</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">an</span> <span class="ow">in</span> <span class="n">atomic_numbers</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">symbols</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Q</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">a</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span>
                       <span class="nb">map</span><span class="p">(</span><span class="nb">chr</span><span class="p">,</span> <span class="nb">range</span><span class="p">(</span><span class="mi">97</span><span class="p">,</span> <span class="mi">97</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">unique_masses</span><span class="p">)))]</span>
        <span class="k">for</span> <span class="n">um</span><span class="p">,</span> <span class="n">s</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">unique_masses</span><span class="p">,</span> <span class="n">symbols</span><span class="p">):</span>
            <span class="n">masses</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">masses</span><span class="p">[</span><span class="s2">&quot;mass&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">um</span><span class="p">,</span> <span class="s2">&quot;element&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">s</span>
        <span class="k">if</span> <span class="n">atom_labels</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>  <span class="c1"># add unique labels based on elements</span>
            <span class="k">for</span> <span class="n">el</span><span class="p">,</span> <span class="n">vc</span> <span class="ow">in</span> <span class="n">masses</span><span class="p">[</span><span class="s2">&quot;element&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">value_counts</span><span class="p">()</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
                <span class="n">masses</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">masses</span><span class="p">[</span><span class="s2">&quot;element&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">el</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">]</span> <span class="o">=</span> \
                    <span class="p">[</span><span class="s2">&quot;</span><span class="si">%s%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">el</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">vc</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
        <span class="k">assert</span> <span class="n">masses</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">nunique</span><span class="p">(</span><span class="n">dropna</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">masses</span><span class="p">),</span> \
            <span class="s2">&quot;Expecting unique atom label for each type&quot;</span>
        <span class="n">mass_info</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">([</span><span class="n">r</span><span class="p">[</span><span class="s2">&quot;label&quot;</span><span class="p">],</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;mass&quot;</span><span class="p">]])</span>
                     <span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">masses</span><span class="o">.</span><span class="n">iterrows</span><span class="p">()]</span>

        <span class="n">nonbond_coeffs</span><span class="p">,</span> <span class="n">topo_coeffs</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">:</span>
            <span class="k">if</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">:</span>
                <span class="n">nbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="s2">&quot;PairIJ Coeffs&quot;</span><span class="p">]</span>
                <span class="n">nbc</span> <span class="o">=</span> <span class="n">nbc</span><span class="o">.</span><span class="n">sort_values</span><span class="p">([</span><span class="s2">&quot;id1&quot;</span><span class="p">,</span> <span class="s2">&quot;id2&quot;</span><span class="p">])</span><span class="o">.</span><span class="n">drop</span><span class="p">([</span><span class="s2">&quot;id1&quot;</span><span class="p">,</span> <span class="s2">&quot;id2&quot;</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">nonbond_coeffs</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">nbc</span><span class="o">.</span><span class="n">itertuples</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">None</span><span class="p">)]</span>
            <span class="k">elif</span> <span class="s2">&quot;Pair Coeffs&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">:</span>
                <span class="n">nbc</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="s2">&quot;Pair Coeffs&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">sort_index</span><span class="p">()</span>
                <span class="n">nonbond_coeffs</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">nbc</span><span class="o">.</span><span class="n">itertuples</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">None</span><span class="p">)]</span>

            <span class="n">topo_coeffs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">][</span><span class="mi">2</span><span class="p">:]</span>
                           <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">}</span>
            <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">topo_coeffs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">class2_coeffs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">v</span><span class="o">.</span><span class="n">itertuples</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">None</span><span class="p">))</span>
                                 <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                                 <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">CLASS2_KEYWORDS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">kw</span><span class="p">,</span> <span class="p">[])}</span>
                <span class="n">ff_df</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">ff_df</span><span class="o">.</span><span class="n">itertuples</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
                    <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;coeffs&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="mi">1</span><span class="p">:]),</span> <span class="s2">&quot;types&quot;</span><span class="p">:</span> <span class="p">[]}</span>
                    <span class="k">if</span> <span class="n">class2_coeffs</span><span class="p">:</span>
                        <span class="n">d</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">t</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">])</span>
                                  <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">class2_coeffs</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>
                    <span class="n">topo_coeffs</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
            <span class="k">def</span> <span class="nf">label_topo</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
                <span class="k">return</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">masses</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">atoms_df</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">t</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">],</span> <span class="s2">&quot;label&quot;</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">ff_kw</span> <span class="o">=</span> <span class="n">k</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot; Coeffs&quot;</span>
                <span class="k">for</span> <span class="n">topo</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">itertuples</span><span class="p">(</span><span class="kc">False</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
                    <span class="n">topo_idx</span> <span class="o">=</span> <span class="n">topo</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span>
                    <span class="n">indices</span> <span class="o">=</span> <span class="n">topo</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
                    <span class="n">mids</span> <span class="o">=</span> <span class="n">atoms_df</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">indices</span><span class="p">,</span> <span class="s2">&quot;molecule-ID&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">unique</span><span class="p">()</span>
                    <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">mids</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> \
                        <span class="s2">&quot;Do not support intermolecular topology formed &quot;</span> \
                        <span class="s2">&quot;by atoms with different molecule-IDs&quot;</span>
                    <span class="n">label</span> <span class="o">=</span> <span class="n">label_topo</span><span class="p">(</span><span class="n">indices</span><span class="p">)</span>
                    <span class="n">topo_coeffs</span><span class="p">[</span><span class="n">ff_kw</span><span class="p">][</span><span class="n">topo_idx</span><span class="p">][</span><span class="s2">&quot;types&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">label</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">data_by_mols</span><span class="p">[</span><span class="n">mids</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">k</span><span class="p">):</span>
                        <span class="n">data_by_mols</span><span class="p">[</span><span class="n">mids</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">indices</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">data_by_mols</span><span class="p">[</span><span class="n">mids</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">indices</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">topo_coeffs</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topo_coeffs</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">v</span><span class="p">:</span>
                    <span class="n">d</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]))</span>

        <span class="n">ff</span> <span class="o">=</span> <span class="n">ForceField</span><span class="p">(</span><span class="n">mass_info</span><span class="o">=</span><span class="n">mass_info</span><span class="p">,</span> <span class="n">nonbond_coeffs</span><span class="o">=</span><span class="n">nonbond_coeffs</span><span class="p">,</span>
                        <span class="n">topo_coeffs</span><span class="o">=</span><span class="n">topo_coeffs</span><span class="p">)</span>

        <span class="n">topo_list</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">mid</span> <span class="ow">in</span> <span class="n">unique_mids</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="n">data_by_mols</span><span class="p">[</span><span class="n">mid</span><span class="p">]</span>
            <span class="n">atoms</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span>
            <span class="n">shift</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">atoms</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
            <span class="n">type_ids</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span>
            <span class="n">species</span> <span class="o">=</span> <span class="n">masses</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">type_ids</span><span class="p">,</span> <span class="s2">&quot;element&quot;</span><span class="p">]</span>
            <span class="n">labels</span> <span class="o">=</span> <span class="n">masses</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">type_ids</span><span class="p">,</span> <span class="s2">&quot;label&quot;</span><span class="p">]</span>
            <span class="n">coords</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">]]</span>
            <span class="n">m</span> <span class="o">=</span> <span class="n">Molecule</span><span class="p">(</span><span class="n">species</span><span class="o">.</span><span class="n">values</span><span class="p">,</span> <span class="n">coords</span><span class="o">.</span><span class="n">values</span><span class="p">,</span>
                         <span class="n">site_properties</span><span class="o">=</span><span class="p">{</span><span class="n">ff_label</span><span class="p">:</span> <span class="n">labels</span><span class="o">.</span><span class="n">values</span><span class="p">})</span>
            <span class="n">charges</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;q&quot;</span><span class="p">)</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[[</span><span class="s2">&quot;vx&quot;</span><span class="p">,</span> <span class="s2">&quot;vy&quot;</span><span class="p">,</span> <span class="s2">&quot;vz&quot;</span><span class="p">]]</span> <span class="k">if</span> <span class="s2">&quot;vx&quot;</span> <span class="ow">in</span> <span class="n">atoms</span><span class="o">.</span><span class="n">columns</span> \
                <span class="k">else</span> <span class="kc">None</span>
            <span class="n">topologies</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">kw</span><span class="p">):</span>
                    <span class="n">topologies</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">kw</span><span class="p">])</span> <span class="o">-</span> <span class="n">shift</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="n">topologies</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">topologies</span> <span class="k">else</span> <span class="n">topologies</span>
            <span class="n">topo_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Topology</span><span class="p">(</span><span class="n">sites</span><span class="o">=</span><span class="n">m</span><span class="p">,</span> <span class="n">ff_label</span><span class="o">=</span><span class="n">ff_label</span><span class="p">,</span>
                                      <span class="n">charges</span><span class="o">=</span><span class="n">charges</span><span class="p">,</span> <span class="n">velocities</span><span class="o">=</span><span class="n">velocities</span><span class="p">,</span>
                                      <span class="n">topologies</span><span class="o">=</span><span class="n">topologies</span><span class="p">))</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">topo_list</span></div>

<div class="viewcode-block" id="LammpsData.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.from_file">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;full&quot;</span><span class="p">,</span> <span class="n">sort_id</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that parses a file.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename to read.</span>
<span class="sd">            atom_style (str): Associated atom_style. Default to &quot;full&quot;.</span>
<span class="sd">            sort_id (bool): Whether sort each section by id. Default to</span>
<span class="sd">                True.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
        <span class="n">kw_pattern</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;|&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span><span class="o">*</span><span class="n">SECTION_KEYWORDS</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
        <span class="n">section_marks</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
                         <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">kw_pattern</span><span class="p">,</span> <span class="n">l</span><span class="p">)]</span>
        <span class="n">parts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">section_marks</span><span class="p">)</span>

        <span class="n">float_group</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;([0-9eE.+-]+)&quot;</span>
        <span class="n">header_pattern</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">header_pattern</span><span class="p">[</span><span class="s2">&quot;counts&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;^\s*(\d+)\s+([a-zA-Z]+)$&quot;</span>
        <span class="n">header_pattern</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;^\s*(\d+)\s+([a-zA-Z]+)\s+types$&quot;</span>
        <span class="n">header_pattern</span><span class="p">[</span><span class="s2">&quot;bounds&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;^\s*</span><span class="si">{}</span><span class="s2">$&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
            <span class="p">[</span><span class="n">float_group</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">+</span> <span class="p">[</span><span class="sa">r</span><span class="s2">&quot;([xyz])lo \3hi&quot;</span><span class="p">]))</span>
        <span class="n">header_pattern</span><span class="p">[</span><span class="s2">&quot;tilt&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;^\s*</span><span class="si">{}</span><span class="s2">$&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\s+&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
            <span class="p">[</span><span class="n">float_group</span><span class="p">]</span> <span class="o">*</span> <span class="mi">3</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;xy xz yz&quot;</span><span class="p">]))</span>

        <span class="n">header</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;counts&quot;</span><span class="p">:</span> <span class="p">{},</span> <span class="s2">&quot;types&quot;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="n">bounds</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">clean_lines</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">:]):</span>  <span class="c1"># skip the 1st line</span>
            <span class="n">match</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">header_pattern</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">match</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">l</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">match</span><span class="p">:</span>
                    <span class="k">break</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">continue</span>
            <span class="k">if</span> <span class="n">match</span> <span class="ow">and</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;counts&quot;</span><span class="p">,</span> <span class="s2">&quot;types&quot;</span><span class="p">]:</span>
                <span class="n">header</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">2</span><span class="p">)]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
            <span class="k">elif</span> <span class="n">match</span> <span class="ow">and</span> <span class="n">k</span> <span class="o">==</span> <span class="s2">&quot;bounds&quot;</span><span class="p">:</span>
                <span class="n">g</span> <span class="o">=</span> <span class="n">match</span><span class="o">.</span><span class="n">groups</span><span class="p">()</span>
                <span class="n">bounds</span><span class="p">[</span><span class="n">g</span><span class="p">[</span><span class="mi">2</span><span class="p">]]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">g</span><span class="p">[:</span><span class="mi">2</span><span class="p">]]</span>
            <span class="k">elif</span> <span class="n">match</span> <span class="ow">and</span> <span class="n">k</span> <span class="o">==</span> <span class="s2">&quot;tilt&quot;</span><span class="p">:</span>
                <span class="n">header</span><span class="p">[</span><span class="s2">&quot;tilt&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">match</span><span class="o">.</span><span class="n">groups</span><span class="p">()]</span>
        <span class="n">header</span><span class="p">[</span><span class="s2">&quot;bounds&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">bounds</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">])</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="s2">&quot;xyz&quot;</span><span class="p">]</span>
        <span class="n">box</span> <span class="o">=</span> <span class="n">LammpsBox</span><span class="p">(</span><span class="n">header</span><span class="p">[</span><span class="s2">&quot;bounds&quot;</span><span class="p">],</span> <span class="n">header</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;tilt&quot;</span><span class="p">))</span>

        <span class="k">def</span> <span class="nf">parse_section</span><span class="p">(</span><span class="n">sec_lines</span><span class="p">):</span>
            <span class="n">title_info</span> <span class="o">=</span> <span class="n">sec_lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">kw</span> <span class="o">=</span> <span class="n">title_info</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
            <span class="n">sio</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">sec_lines</span><span class="p">[</span><span class="mi">2</span><span class="p">:]))</span>  <span class="c1"># skip the 2nd line</span>
            <span class="k">if</span> <span class="n">kw</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;Coeffs&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">kw</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;PairIJ&quot;</span><span class="p">):</span>
                <span class="n">df_list</span> <span class="o">=</span> <span class="p">[</span><span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="n">StringIO</span><span class="p">(</span><span class="n">line</span><span class="p">),</span> <span class="n">header</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;#&quot;</span><span class="p">,</span>
                                       <span class="n">delim_whitespace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">sec_lines</span><span class="p">[</span><span class="mi">2</span><span class="p">:]</span> <span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()]</span>
                <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">df_list</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;coeff</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span>
                                  <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="n">sio</span><span class="p">,</span> <span class="n">header</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;#&quot;</span><span class="p">,</span>
                                 <span class="n">delim_whitespace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">kw</span> <span class="o">==</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span><span class="p">:</span>
                    <span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;id1&quot;</span><span class="p">,</span> <span class="s2">&quot;id2&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;coeff</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span>
                                              <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)]</span>
                    <span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">elif</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_HEADERS</span><span class="p">:</span>
                    <span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_HEADERS</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">kw</span> <span class="o">==</span> <span class="s2">&quot;Atoms&quot;</span><span class="p">:</span>
                    <span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">ATOMS_HEADERS</span><span class="p">[</span><span class="n">atom_style</span><span class="p">]</span>
                    <span class="k">if</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">names</span><span class="p">):</span>
                        <span class="k">pass</span>
                    <span class="k">elif</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">names</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span><span class="p">:</span>
                        <span class="n">names</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;nx&quot;</span><span class="p">,</span> <span class="s2">&quot;ny&quot;</span><span class="p">,</span> <span class="s2">&quot;nz&quot;</span><span class="p">]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Format in Atoms section inconsistent&quot;</span>
                                         <span class="s2">&quot; with atom_style </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">atom_style</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s2">&quot;Parser for </span><span class="si">%s</span><span class="s2"> section&quot;</span>
                                              <span class="s2">&quot; not implemented&quot;</span> <span class="o">%</span> <span class="n">kw</span><span class="p">)</span>
            <span class="n">df</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="n">names</span>
            <span class="k">if</span> <span class="n">sort_id</span><span class="p">:</span>
                <span class="n">sort_by</span> <span class="o">=</span> <span class="s2">&quot;id&quot;</span> <span class="k">if</span> <span class="n">kw</span> <span class="o">!=</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span> <span class="k">else</span> <span class="p">[</span><span class="s2">&quot;id1&quot;</span><span class="p">,</span> <span class="s2">&quot;id2&quot;</span><span class="p">]</span>
                <span class="n">df</span><span class="o">.</span><span class="n">sort_values</span><span class="p">(</span><span class="n">sort_by</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="k">if</span> <span class="s2">&quot;id&quot;</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
                <span class="n">df</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s2">&quot;id&quot;</span><span class="p">,</span> <span class="n">drop</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">return</span> <span class="n">kw</span><span class="p">,</span> <span class="n">df</span>

        <span class="n">err_msg</span> <span class="o">=</span> <span class="s2">&quot;Bad LAMMPS data format where &quot;</span>
        <span class="n">body</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">seen_atoms</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">part</span> <span class="ow">in</span> <span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">name</span><span class="p">,</span> <span class="n">section</span> <span class="o">=</span> <span class="n">parse_section</span><span class="p">(</span><span class="n">part</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;Atoms&quot;</span><span class="p">:</span>
                <span class="n">seen_atoms</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Velocities&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]</span> <span class="ow">and</span> \
                    <span class="ow">not</span> <span class="n">seen_atoms</span><span class="p">:</span>  <span class="c1"># Atoms must appear earlier than these</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">err_msg</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> section appears before&quot;</span>
                                             <span class="s2">&quot; Atoms section&quot;</span> <span class="o">%</span> <span class="n">name</span><span class="p">)</span>
            <span class="n">body</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">name</span><span class="p">:</span> <span class="n">section</span><span class="p">})</span>

        <span class="n">err_msg</span> <span class="o">+=</span> <span class="s2">&quot;Nos. of </span><span class="si">{}</span><span class="s2"> do not match between header and </span><span class="si">{}</span><span class="s2"> section&quot;</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">[</span><span class="s2">&quot;Masses&quot;</span><span class="p">])</span> <span class="o">==</span> <span class="n">header</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">][</span><span class="s2">&quot;atom&quot;</span><span class="p">],</span> \
            <span class="n">err_msg</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;atom types&quot;</span><span class="p">,</span> <span class="s2">&quot;Masses&quot;</span><span class="p">)</span>
        <span class="n">atom_sections</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">,</span> <span class="s2">&quot;Velocities&quot;</span><span class="p">]</span> \
            <span class="k">if</span> <span class="s2">&quot;Velocities&quot;</span> <span class="ow">in</span> <span class="n">body</span> <span class="k">else</span> <span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">atom_sections</span><span class="p">:</span>
            <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">[</span><span class="n">s</span><span class="p">])</span> <span class="o">==</span> <span class="n">header</span><span class="p">[</span><span class="s2">&quot;counts&quot;</span><span class="p">][</span><span class="s2">&quot;atoms&quot;</span><span class="p">],</span> \
                <span class="n">err_msg</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;atoms&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]:</span>
            <span class="k">if</span> <span class="n">header</span><span class="p">[</span><span class="s2">&quot;counts&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="mi">0</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">body</span><span class="p">[</span><span class="n">s</span><span class="p">])</span> <span class="o">==</span> <span class="n">header</span><span class="p">[</span><span class="s2">&quot;counts&quot;</span><span class="p">][</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">()],</span> \
                    <span class="n">err_msg</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">s</span><span class="p">)</span>

        <span class="n">items</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span> <span class="n">body</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Masses&quot;</span><span class="p">,</span> <span class="s2">&quot;Atoms&quot;</span><span class="p">]}</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">body</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;Velocities&quot;</span><span class="p">)</span>
        <span class="n">ff_kws</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">body</span> <span class="k">if</span> <span class="n">k</span>
                  <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;class2&quot;</span><span class="p">]]</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;force_field&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">body</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">ff_kws</span><span class="p">}</span> <span class="k">if</span> <span class="n">ff_kws</span> \
            <span class="k">else</span> <span class="kc">None</span>
        <span class="n">topo_kws</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">body</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]]</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">body</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">topo_kws</span><span class="p">}</span> \
            <span class="k">if</span> <span class="n">topo_kws</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;atom_style&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">atom_style</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;box&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">box</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">items</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsData.from_ff_and_topologies"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.from_ff_and_topologies">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_ff_and_topologies</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">box</span><span class="p">,</span> <span class="n">ff</span><span class="p">,</span> <span class="n">topologies</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;full&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor building LammpsData from a ForceField object and a</span>
<span class="sd">        list of Topology objects. Do not support intermolecular</span>
<span class="sd">        topologies since a Topology object includes data for ONE</span>
<span class="sd">        molecule or structure only.</span>

<span class="sd">        Args:</span>
<span class="sd">            box (LammpsBox): Simulation box.</span>
<span class="sd">            ff (ForceField): ForceField object with data for Masses and</span>
<span class="sd">                force field sections.</span>
<span class="sd">            topologies ([Topology]): List of Topology objects with data</span>
<span class="sd">                for Atoms, Velocities and topology sections.</span>
<span class="sd">            atom_style (str): Output atom_style. Default to &quot;full&quot;.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">atom_types</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">species</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">topologies</span><span class="p">])</span>
        <span class="k">assert</span> <span class="n">atom_types</span><span class="o">.</span><span class="n">issubset</span><span class="p">(</span><span class="n">ff</span><span class="o">.</span><span class="n">maps</span><span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()),</span> \
            <span class="s2">&quot;Unknown atom type found in topologies&quot;</span>

        <span class="n">items</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">box</span><span class="o">=</span><span class="n">box</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="n">atom_style</span><span class="p">,</span> <span class="n">masses</span><span class="o">=</span><span class="n">ff</span><span class="o">.</span><span class="n">masses</span><span class="p">,</span>
                     <span class="n">force_field</span><span class="o">=</span><span class="n">ff</span><span class="o">.</span><span class="n">force_field</span><span class="p">)</span>

        <span class="n">mol_ids</span><span class="p">,</span> <span class="n">charges</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[]</span>
        <span class="n">v_collector</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">if</span> <span class="n">topologies</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">velocities</span> <span class="k">else</span> <span class="kc">None</span>
        <span class="n">topo_collector</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Bonds&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;Angles&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;Dihedrals&quot;</span><span class="p">:</span> <span class="p">[],</span>
                          <span class="s2">&quot;Impropers&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="n">topo_labels</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Bonds&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;Angles&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;Dihedrals&quot;</span><span class="p">:</span> <span class="p">[],</span>
                       <span class="s2">&quot;Impropers&quot;</span><span class="p">:</span> <span class="p">[]}</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">topo</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">topologies</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">topo</span><span class="o">.</span><span class="n">topologies</span><span class="p">:</span>
                <span class="n">shift</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">labels</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topo</span><span class="o">.</span><span class="n">topologies</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">topo_collector</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">+</span> <span class="n">shift</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
                    <span class="n">topo_labels</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">tuple</span><span class="p">([</span><span class="n">topo</span><span class="o">.</span><span class="n">type_by_sites</span><span class="p">[</span><span class="n">j</span><span class="p">]</span>
                                                  <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">t</span><span class="p">])</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">v</span><span class="p">])</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v_collector</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">v_collector</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">topo</span><span class="o">.</span><span class="n">velocities</span><span class="p">)</span>
            <span class="n">mol_ids</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">topo</span><span class="o">.</span><span class="n">sites</span><span class="p">))</span>
            <span class="n">labels</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">topo</span><span class="o">.</span><span class="n">type_by_sites</span><span class="p">)</span>
            <span class="n">coords</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">topo</span><span class="o">.</span><span class="n">sites</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">)</span>
            <span class="n">q</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">topo</span><span class="o">.</span><span class="n">sites</span><span class="p">)</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">topo</span><span class="o">.</span><span class="n">charges</span> <span class="k">else</span> <span class="n">topo</span><span class="o">.</span><span class="n">charges</span>
            <span class="n">charges</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">q</span><span class="p">)</span>

        <span class="n">atoms</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">coords</span><span class="p">),</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="s2">&quot;z&quot;</span><span class="p">])</span>
        <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;molecule-ID&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">mol_ids</span>
        <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;q&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">charges</span>
        <span class="n">atoms</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">ff</span><span class="o">.</span><span class="n">maps</span><span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="n">labels</span><span class="p">))</span>
        <span class="n">atoms</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="n">atoms</span><span class="p">[</span><span class="n">ATOMS_HEADERS</span><span class="p">[</span><span class="n">atom_style</span><span class="p">]]</span>

        <span class="n">velocities</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">v_collector</span><span class="p">:</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">v_collector</span><span class="p">),</span>
                                      <span class="n">columns</span><span class="o">=</span><span class="n">SECTION_HEADERS</span><span class="p">[</span><span class="s2">&quot;Velocities&quot;</span><span class="p">])</span>
            <span class="n">velocities</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="n">topology</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="kc">None</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topo_labels</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">}</span>
        <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">topology</span><span class="p">:</span>
            <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">(</span><span class="n">topo_collector</span><span class="p">[</span><span class="n">k</span><span class="p">]),</span>
                              <span class="n">columns</span><span class="o">=</span><span class="n">SECTION_HEADERS</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="mi">1</span><span class="p">:])</span>
            <span class="n">df</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">ff</span><span class="o">.</span><span class="n">maps</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="n">topo_labels</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
            <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">isnull</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">])):</span>  <span class="c1"># Throw away undefined topologies</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Undefined </span><span class="si">%s</span><span class="s2"> detected and removed&quot;</span> <span class="o">%</span> <span class="n">k</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
                <span class="n">df</span><span class="o">.</span><span class="n">dropna</span><span class="p">(</span><span class="n">subset</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">],</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">df</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">drop</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">df</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">topology</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="n">SECTION_HEADERS</span><span class="p">[</span><span class="n">k</span><span class="p">]]</span>
        <span class="n">topology</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topology</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">v</span><span class="o">.</span><span class="n">empty</span><span class="p">}</span>

        <span class="n">items</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;atoms&quot;</span><span class="p">:</span> <span class="n">atoms</span><span class="p">,</span> <span class="s2">&quot;velocities&quot;</span><span class="p">:</span> <span class="n">velocities</span><span class="p">,</span>
                      <span class="s2">&quot;topology&quot;</span><span class="p">:</span> <span class="n">topology</span><span class="p">})</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">items</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsData.from_structure"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.from_structure">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_structure</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">ff_elements</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;charge&quot;</span><span class="p">,</span>
                       <span class="n">is_sort</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Simple constructor building LammpsData from a structure without</span>
<span class="sd">        force field parameters and topologies.</span>

<span class="sd">        Args:</span>
<span class="sd">            structure (Structure): Input structure.</span>
<span class="sd">            ff_elements ([str]): List of strings of elements that must</span>
<span class="sd">                be present due to force field settings but not</span>
<span class="sd">                necessarily in the structure. Default to None.</span>
<span class="sd">            atom_style (str): Choose between &quot;atomic&quot; (neutral) and</span>
<span class="sd">                &quot;charge&quot; (charged). Default to &quot;charge&quot;.</span>
<span class="sd">            is_sort (bool): whether to sort sites</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">is_sort</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">get_sorted_structure</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">box</span><span class="p">,</span> <span class="n">symmop</span> <span class="o">=</span> <span class="n">lattice_2_lmpbox</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="p">)</span>
        <span class="n">coords</span> <span class="o">=</span> <span class="n">symmop</span><span class="o">.</span><span class="n">operate_multi</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">cart_coords</span><span class="p">)</span>
        <span class="n">site_properties</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">site_properties</span>
        <span class="k">if</span> <span class="s2">&quot;velocities&quot;</span> <span class="ow">in</span> <span class="n">site_properties</span><span class="p">:</span>
            <span class="n">velos</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">site_properties</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">])</span>
            <span class="n">rot</span> <span class="o">=</span> <span class="n">SymmOp</span><span class="o">.</span><span class="n">from_rotation_and_translation</span><span class="p">(</span><span class="n">symmop</span><span class="o">.</span><span class="n">rotation_matrix</span><span class="p">)</span>
            <span class="n">rot_velos</span> <span class="o">=</span> <span class="n">rot</span><span class="o">.</span><span class="n">operate_multi</span><span class="p">(</span><span class="n">velos</span><span class="p">)</span>
            <span class="n">site_properties</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;velocities&quot;</span><span class="p">:</span> <span class="n">rot_velos</span><span class="p">})</span>
        <span class="n">boxed_s</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="n">box</span><span class="o">.</span><span class="n">to_lattice</span><span class="p">(),</span> <span class="n">s</span><span class="o">.</span><span class="n">species</span><span class="p">,</span> <span class="n">coords</span><span class="p">,</span>
                            <span class="n">site_properties</span><span class="o">=</span><span class="n">site_properties</span><span class="p">,</span>
                            <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="n">symbols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">symbol_set</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ff_elements</span><span class="p">:</span>
            <span class="n">symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">ff_elements</span><span class="p">)</span>
        <span class="n">elements</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">el</span><span class="p">)</span> <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">(</span><span class="n">symbols</span><span class="p">))</span>
        <span class="n">mass_info</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">([</span><span class="n">i</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">elements</span><span class="p">]</span>
        <span class="n">ff</span> <span class="o">=</span> <span class="n">ForceField</span><span class="p">(</span><span class="n">mass_info</span><span class="p">)</span>
        <span class="n">topo</span> <span class="o">=</span> <span class="n">Topology</span><span class="p">(</span><span class="n">boxed_s</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">from_ff_and_topologies</span><span class="p">(</span><span class="n">box</span><span class="o">=</span><span class="n">box</span><span class="p">,</span> <span class="n">ff</span><span class="o">=</span><span class="n">ff</span><span class="p">,</span> <span class="n">topologies</span><span class="o">=</span><span class="p">[</span><span class="n">topo</span><span class="p">],</span>
                                          <span class="n">atom_style</span><span class="o">=</span><span class="n">atom_style</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsData.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that reads in a dictionary.</span>

<span class="sd">        Args:</span>
<span class="sd">            d (dict): Dictionary to read.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">decode_df</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_json</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">orient</span><span class="o">=</span><span class="s2">&quot;split&quot;</span><span class="p">)</span>
        <span class="n">items</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;box&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">LammpsBox</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;box&quot;</span><span class="p">])</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;masses&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">decode_df</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;masses&quot;</span><span class="p">])</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;atoms&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">decode_df</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;atoms&quot;</span><span class="p">])</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;atom_style&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;atom_style&quot;</span><span class="p">]</span>

        <span class="n">velocities</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">velocities</span><span class="p">:</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="n">decode_df</span><span class="p">(</span><span class="n">velocities</span><span class="p">)</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">velocities</span>
        <span class="n">force_field</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;force_field&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">force_field</span><span class="p">:</span>
            <span class="n">force_field</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">decode_df</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">force_field</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;force_field&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">force_field</span>
        <span class="n">topology</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">topology</span><span class="p">:</span>
            <span class="n">topology</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">decode_df</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topology</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">items</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">topology</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="o">**</span><span class="n">items</span><span class="p">)</span></div>

<div class="viewcode-block" id="LammpsData.as_dict"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.LammpsData.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the LammpsData as a dict.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">encode_df</span><span class="p">(</span><span class="n">df</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">df</span><span class="o">.</span><span class="n">to_json</span><span class="p">(</span><span class="n">orient</span><span class="o">=</span><span class="s2">&quot;split&quot;</span><span class="p">)</span>
        <span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@module&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;@class&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;box&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">box</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;masses&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">encode_df</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">masses</span><span class="p">)</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;atoms&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">encode_df</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="p">)</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;atom_style&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atom_style</span>

        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;velocities&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="ow">is</span> <span class="kc">None</span> \
            <span class="k">else</span> <span class="n">encode_df</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">velocities</span><span class="p">)</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;force_field&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span> \
            <span class="k">else</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">encode_df</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span> \
            <span class="k">else</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">encode_df</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
        <span class="k">return</span> <span class="n">d</span></div></div>


<div class="viewcode-block" id="Topology"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.Topology">[docs]</a><span class="k">class</span> <span class="nc">Topology</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class carrying most data in Atoms, Velocities and molecular</span>
<span class="sd">    topology sections for ONE SINGLE Molecule or Structure</span>
<span class="sd">    object, or a plain list of Sites.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sites</span><span class="p">,</span> <span class="n">ff_label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">charges</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">velocities</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">topologies</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        Args:</span>
<span class="sd">            sites ([Site] or SiteCollection): A group of sites in a</span>
<span class="sd">                list or as a Molecule/Structure.</span>
<span class="sd">            ff_label (str): Site property key for labeling atoms of</span>
<span class="sd">                different types. Default to None, i.e., use</span>
<span class="sd">                site.species_string.</span>
<span class="sd">            charges ([q, ...]): Charge of each site in a (n,)</span>
<span class="sd">                array/list, where n is the No. of sites. Default to</span>
<span class="sd">                None, i.e., search site property for charges.</span>
<span class="sd">            velocities ([[vx, vy, vz], ...]): Velocity of each site in</span>
<span class="sd">                a (n, 3) array/list, where n is the No. of sites.</span>
<span class="sd">                Default to None, i.e., search site property for</span>
<span class="sd">                velocities.</span>
<span class="sd">            topologies (dict): Bonds, angles, dihedrals and improper</span>
<span class="sd">                dihedrals defined by site indices. Default to None,</span>
<span class="sd">                i.e., no additional topology. All four valid keys</span>
<span class="sd">                listed below are optional.</span>
<span class="sd">                {</span>
<span class="sd">                    &quot;Bonds&quot;: [[i, j], ...],</span>
<span class="sd">                    &quot;Angles&quot;: [[i, j, k], ...],</span>
<span class="sd">                    &quot;Dihedrals&quot;: [[i, j, k, l], ...],</span>
<span class="sd">                    &quot;Impropers&quot;: [[i, j, k, l], ...]</span>
<span class="sd">                }</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">sites</span><span class="p">,</span> <span class="p">(</span><span class="n">Molecule</span><span class="p">,</span> <span class="n">Structure</span><span class="p">)):</span>
            <span class="n">sites</span> <span class="o">=</span> <span class="n">Molecule</span><span class="o">.</span><span class="n">from_sites</span><span class="p">(</span><span class="n">sites</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">ff_label</span><span class="p">:</span>
            <span class="n">type_by_sites</span> <span class="o">=</span> <span class="n">sites</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ff_label</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">type_by_sites</span> <span class="o">=</span> <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">sites</span><span class="p">]</span>
        <span class="c1"># search for site property if not override</span>
        <span class="k">if</span> <span class="n">charges</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">charges</span> <span class="o">=</span> <span class="n">sites</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;charge&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">velocities</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="n">sites</span><span class="o">.</span><span class="n">site_properties</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;velocities&quot;</span><span class="p">)</span>
        <span class="c1"># validate shape</span>
        <span class="k">if</span> <span class="n">charges</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">charge_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">charges</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">charge_arr</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sites</span><span class="p">),),</span> \
                <span class="s2">&quot;Wrong format for charges&quot;</span>
            <span class="n">charges</span> <span class="o">=</span> <span class="n">charge_arr</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">velocities</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">velocities_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">velocities</span><span class="p">)</span>
            <span class="k">assert</span> <span class="n">velocities_arr</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sites</span><span class="p">),</span> <span class="mi">3</span><span class="p">),</span> \
                <span class="s2">&quot;Wrong format for velocities&quot;</span>
            <span class="n">velocities</span> <span class="o">=</span> <span class="n">velocities_arr</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">topologies</span><span class="p">:</span>
            <span class="n">topologies</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">topologies</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                          <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">sites</span> <span class="o">=</span> <span class="n">sites</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">ff_label</span> <span class="o">=</span> <span class="n">ff_label</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">charges</span> <span class="o">=</span> <span class="n">charges</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="o">=</span> <span class="n">velocities</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">topologies</span> <span class="o">=</span> <span class="n">topologies</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type_by_sites</span> <span class="o">=</span> <span class="n">type_by_sites</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">species</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">type_by_sites</span><span class="p">)</span>

<div class="viewcode-block" id="Topology.from_bonding"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.Topology.from_bonding">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_bonding</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">molecule</span><span class="p">,</span> <span class="n">bond</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dihedral</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                     <span class="n">tol</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Another constructor that creates an instance from a molecule.</span>
<span class="sd">        Covalent bonds and other bond-based topologies (angles and</span>
<span class="sd">        dihedrals) can be automatically determined. Cannot be used for</span>
<span class="sd">        non bond-based topologies, e.g., improper dihedrals.</span>

<span class="sd">        Args:</span>
<span class="sd">            molecule (Molecule): Input molecule.</span>
<span class="sd">            bond (bool): Whether find bonds. If set to False, angle and</span>
<span class="sd">                dihedral searching will be skipped. Default to True.</span>
<span class="sd">            angle (bool): Whether find angles. Default to True.</span>
<span class="sd">            dihedral (bool): Whether find dihedrals. Default to True.</span>
<span class="sd">            tol (float): Bond distance tolerance. Default to 0.1.</span>
<span class="sd">                Not recommended to alter.</span>
<span class="sd">            **kwargs: Other kwargs supported by Topology.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">real_bonds</span> <span class="o">=</span> <span class="n">molecule</span><span class="o">.</span><span class="n">get_covalent_bonds</span><span class="p">(</span><span class="n">tol</span><span class="o">=</span><span class="n">tol</span><span class="p">)</span>
        <span class="n">bond_list</span> <span class="o">=</span> <span class="p">[</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">molecule</span><span class="o">.</span><span class="n">index</span><span class="p">,</span> <span class="p">[</span><span class="n">b</span><span class="o">.</span><span class="n">site1</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">site2</span><span class="p">]))</span>
                     <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">real_bonds</span><span class="p">]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">all</span><span class="p">((</span><span class="n">bond</span><span class="p">,</span> <span class="n">bond_list</span><span class="p">)):</span>
            <span class="c1"># do not search for others if not searching for bonds or no bonds</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">sites</span><span class="o">=</span><span class="n">molecule</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">angle_list</span><span class="p">,</span> <span class="n">dihedral_list</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>
            <span class="n">dests</span><span class="p">,</span> <span class="n">freq</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">bond_list</span><span class="p">,</span> <span class="n">return_counts</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">hubs</span> <span class="o">=</span> <span class="n">dests</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">where</span><span class="p">(</span><span class="n">freq</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">)]</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
            <span class="n">bond_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">bond_list</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">hubs</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">hub_spokes</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="k">for</span> <span class="n">hub</span> <span class="ow">in</span> <span class="n">hubs</span><span class="p">:</span>
                    <span class="n">ix</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isin</span><span class="p">(</span><span class="n">bond_arr</span><span class="p">,</span> <span class="n">hub</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
                    <span class="n">bonds</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">bond_arr</span><span class="p">[</span><span class="n">ix</span><span class="p">])</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span>
                    <span class="n">bonds</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">hub</span><span class="p">)</span>
                    <span class="n">hub_spokes</span><span class="p">[</span><span class="n">hub</span><span class="p">]</span> <span class="o">=</span> <span class="n">bonds</span>
            <span class="c1"># skip angle or dihedral searching if too few bonds or hubs</span>
            <span class="n">dihedral</span> <span class="o">=</span> <span class="kc">False</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bond_list</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">3</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">hubs</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">2</span> \
                <span class="k">else</span> <span class="n">dihedral</span>
            <span class="n">angle</span> <span class="o">=</span> <span class="kc">False</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">bond_list</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">hubs</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">angle</span>

            <span class="k">if</span> <span class="n">angle</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">hub_spokes</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                    <span class="n">angle_list</span><span class="o">.</span><span class="n">extend</span><span class="p">([[</span><span class="n">i</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">j</span><span class="p">]</span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span>
                                       <span class="n">itertools</span><span class="o">.</span><span class="n">combinations</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="mi">2</span><span class="p">)])</span>
            <span class="k">if</span> <span class="n">dihedral</span><span class="p">:</span>
                <span class="n">hub_cons</span> <span class="o">=</span> <span class="n">bond_arr</span><span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">all</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">isin</span><span class="p">(</span><span class="n">bond_arr</span><span class="p">,</span> <span class="n">hubs</span><span class="p">),</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)]</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">hub_cons</span><span class="o">.</span><span class="n">tolist</span><span class="p">():</span>
                    <span class="n">ks</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">hub_spokes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="n">j</span><span class="p">]</span>
                    <span class="n">ls</span> <span class="o">=</span> <span class="p">[</span><span class="n">l</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">hub_spokes</span><span class="p">[</span><span class="n">j</span><span class="p">]</span> <span class="k">if</span> <span class="n">l</span> <span class="o">!=</span> <span class="n">i</span><span class="p">]</span>
                    <span class="n">dihedral_list</span><span class="o">.</span><span class="n">extend</span><span class="p">([[</span><span class="n">k</span><span class="p">,</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span><span class="p">,</span> <span class="n">l</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span>
                                          <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="n">ls</span><span class="p">)</span>
                                          <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="n">l</span><span class="p">])</span>

            <span class="n">topologies</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span>
                          <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">][:</span><span class="mi">3</span><span class="p">],</span>
                                 <span class="p">[</span><span class="n">bond_list</span><span class="p">,</span> <span class="n">angle_list</span><span class="p">,</span> <span class="n">dihedral_list</span><span class="p">])</span>
                          <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">}</span>
            <span class="n">topologies</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">topologies</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">topologies</span>
            <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">sites</span><span class="o">=</span><span class="n">molecule</span><span class="p">,</span> <span class="n">topologies</span><span class="o">=</span><span class="n">topologies</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="ForceField"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.ForceField">[docs]</a><span class="k">class</span> <span class="nc">ForceField</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class carrying most data in Masses and force field sections.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        masses (pandas.DataFrame): DataFrame for Masses section.</span>
<span class="sd">        force_field (dict): Force field section keywords (keys) and</span>
<span class="sd">            data (values) as DataFrames.</span>
<span class="sd">        maps (dict): Dict for labeling atoms and topologies.</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">_is_valid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">df</span><span class="p">):</span>
        <span class="k">return</span> <span class="ow">not</span> <span class="n">pd</span><span class="o">.</span><span class="n">isnull</span><span class="p">(</span><span class="n">df</span><span class="p">)</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">any</span><span class="p">()</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mass_info</span><span class="p">,</span> <span class="n">nonbond_coeffs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">topo_coeffs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        Args:</span>
<span class="sd">            mass_into (list): List of atomic mass info. Elements,</span>
<span class="sd">                strings (symbols) and floats are all acceptable for the</span>
<span class="sd">                values, with the first two converted to the atomic mass</span>
<span class="sd">                of an element. It is recommended to use</span>
<span class="sd">                OrderedDict.items() to prevent key duplications.</span>
<span class="sd">                [(&quot;C&quot;, 12.01), (&quot;H&quot;, Element(&quot;H&quot;)), (&quot;O&quot;, &quot;O&quot;), ...]</span>
<span class="sd">            nonbond_coeffs [coeffs]: List of pair or pairij</span>
<span class="sd">                coefficients, of which the sequence must be sorted</span>
<span class="sd">                according to the species in mass_dict. Pair or PairIJ</span>
<span class="sd">                determined by the length of list. Optional with default</span>
<span class="sd">                to None.</span>
<span class="sd">            topo_coeffs (dict): Dict with force field coefficients for</span>
<span class="sd">                molecular topologies. Optional with default</span>
<span class="sd">                to None. All four valid keys listed below are optional.</span>
<span class="sd">                Each value is a list of dicts with non optional keys</span>
<span class="sd">                &quot;coeffs&quot; and &quot;types&quot;, and related class2 force field</span>
<span class="sd">                keywords as optional keys.</span>
<span class="sd">                {</span>
<span class="sd">                    &quot;Bond Coeffs&quot;:</span>
<span class="sd">                        [{&quot;coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;types&quot;: [(&quot;C&quot;, &quot;C&quot;), ...]}, ...],</span>
<span class="sd">                    &quot;Angle Coeffs&quot;:</span>
<span class="sd">                        [{&quot;coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;BondBond Coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;types&quot;: [(&quot;H&quot;, &quot;C&quot;, &quot;H&quot;), ...]}, ...],</span>
<span class="sd">                    &quot;Dihedral Coeffs&quot;:</span>
<span class="sd">                        [{&quot;coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;BondBond13 Coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;types&quot;: [(&quot;H&quot;, &quot;C&quot;, &quot;C&quot;, &quot;H&quot;), ...]}, ...],</span>
<span class="sd">                    &quot;Improper Coeffs&quot;:</span>
<span class="sd">                        [{&quot;coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;AngleAngle Coeffs&quot;: [coeff],</span>
<span class="sd">                          &quot;types&quot;: [(&quot;H&quot;, &quot;C&quot;, &quot;C&quot;, &quot;H&quot;), ...]}, ...],</span>
<span class="sd">                }</span>
<span class="sd">                Topology of same type or equivalent types (e.g.,</span>
<span class="sd">                (&quot;C&quot;, &quot;H&quot;) and (&quot;H&quot;, &quot;C&quot;) bonds) are NOT ALLOWED to</span>
<span class="sd">                be defined MORE THAN ONCE with DIFFERENT coefficients.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">def</span> <span class="nf">map_mass</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">v</span><span class="o">.</span><span class="n">atomic_mass</span><span class="o">.</span><span class="n">real</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">Element</span><span class="p">)</span> <span class="k">else</span> <span class="n">Element</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="o">.</span><span class="n">atomic_mass</span><span class="o">.</span><span class="n">real</span> \
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="k">else</span> <span class="n">v</span>
        <span class="n">index</span><span class="p">,</span> <span class="n">masses</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_info</span><span class="p">,</span> <span class="n">atoms_map</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">m</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">mass_info</span><span class="p">):</span>
            <span class="n">index</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">mass</span> <span class="o">=</span> <span class="n">map_mass</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
            <span class="n">masses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mass</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">mass_info</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">mass</span><span class="p">))</span>
            <span class="n">atoms_map</span><span class="p">[</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">masses</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">({</span><span class="s2">&quot;mass&quot;</span><span class="p">:</span> <span class="n">masses</span><span class="p">},</span> <span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">maps</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Atoms&quot;</span><span class="p">:</span> <span class="n">atoms_map</span><span class="p">}</span>

        <span class="n">ff_dfs</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">nonbond_coeffs</span> <span class="o">=</span> <span class="n">nonbond_coeffs</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nonbond_coeffs</span><span class="p">:</span>
            <span class="n">ff_dfs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_process_nonbond</span><span class="p">())</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span> <span class="o">=</span> <span class="n">topo_coeffs</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                                <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">][</span><span class="mi">2</span><span class="p">:]}</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">coeffs</span><span class="p">,</span> <span class="n">mapper</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process_topo</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
                <span class="n">ff_dfs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">coeffs</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">maps</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ff_dfs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">ff_dfs</span>

    <span class="k">def</span> <span class="nf">_process_nonbond</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">pair_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nonbond_coeffs</span><span class="p">)</span>
        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_valid</span><span class="p">(</span><span class="n">pair_df</span><span class="p">),</span> \
            <span class="s2">&quot;Invalid nonbond coefficients with rows varying in length&quot;</span>
        <span class="n">npair</span><span class="p">,</span> <span class="n">ncoeff</span> <span class="o">=</span> <span class="n">pair_df</span><span class="o">.</span><span class="n">shape</span>
        <span class="n">pair_df</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;coeff</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">ncoeff</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
        <span class="n">nm</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mass_info</span><span class="p">)</span>
        <span class="n">ncomb</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">nm</span> <span class="o">*</span> <span class="p">(</span><span class="n">nm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">npair</span> <span class="o">==</span> <span class="n">nm</span><span class="p">:</span>
            <span class="n">kw</span> <span class="o">=</span> <span class="s2">&quot;Pair Coeffs&quot;</span>
            <span class="n">pair_df</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">nm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">npair</span> <span class="o">==</span> <span class="n">ncomb</span><span class="p">:</span>
            <span class="n">kw</span> <span class="o">=</span> <span class="s2">&quot;PairIJ Coeffs&quot;</span>
            <span class="n">ids</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span>
                       <span class="n">combinations_with_replacement</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">nm</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
            <span class="n">id_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ids</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;id1&quot;</span><span class="p">,</span> <span class="s2">&quot;id2&quot;</span><span class="p">])</span>
            <span class="n">pair_df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">id_df</span><span class="p">,</span> <span class="n">pair_df</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Expecting </span><span class="si">{}</span><span class="s2"> Pair Coeffs or &quot;</span>
                             <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> PairIJ Coeffs for </span><span class="si">{}</span><span class="s2"> atom types,&quot;</span>
                             <span class="s2">&quot; got </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">nm</span><span class="p">,</span> <span class="n">ncomb</span><span class="p">,</span> <span class="n">nm</span><span class="p">,</span> <span class="n">npair</span><span class="p">))</span>
        <span class="k">return</span> <span class="p">{</span><span class="n">kw</span><span class="p">:</span> <span class="n">pair_df</span><span class="p">}</span>

    <span class="k">def</span> <span class="nf">_process_topo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kw</span><span class="p">):</span>

        <span class="k">def</span> <span class="nf">find_eq_types</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">section</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">section</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;Improper&quot;</span><span class="p">):</span>
                <span class="n">label_arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">label</span><span class="p">)</span>
                <span class="n">seqs</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
                        <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]]</span>
                <span class="k">return</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">(</span><span class="n">label_arr</span><span class="p">[</span><span class="n">s</span><span class="p">])</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">seqs</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[</span><span class="n">label</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="n">label</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span>

        <span class="n">main_data</span><span class="p">,</span> <span class="n">distinct_types</span> <span class="o">=</span> <span class="p">[],</span> <span class="p">[]</span>
        <span class="n">class2_data</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="p">[</span><span class="n">kw</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
                       <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">CLASS2_KEYWORDS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">kw</span><span class="p">,</span> <span class="p">[])}</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="p">[</span><span class="n">kw</span><span class="p">]):</span>
            <span class="n">main_data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;coeffs&quot;</span><span class="p">])</span>
            <span class="n">distinct_types</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">class2_data</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                <span class="n">class2_data</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])</span>
        <span class="n">distinct_types</span> <span class="o">=</span> <span class="p">[</span><span class="nb">set</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span>
                              <span class="n">chain</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="n">find_eq_types</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">kw</span><span class="p">)</span>
                                      <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">dt</span><span class="p">]))</span> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">distinct_types</span><span class="p">]</span>
        <span class="n">type_counts</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="nb">len</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span> <span class="k">for</span> <span class="n">dt</span> <span class="ow">in</span> <span class="n">distinct_types</span><span class="p">])</span>
        <span class="n">type_union</span> <span class="o">=</span> <span class="nb">set</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="o">*</span><span class="n">distinct_types</span><span class="p">)</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">type_union</span><span class="p">)</span> <span class="o">==</span> <span class="n">type_counts</span><span class="p">,</span> <span class="s2">&quot;Duplicated items found &quot;</span> \
                                               <span class="s2">&quot;under different coefficients in </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">kw</span>
        <span class="n">atoms</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">ravel</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span><span class="o">*</span><span class="n">distinct_types</span><span class="p">))))</span>
        <span class="k">assert</span> <span class="n">atoms</span><span class="o">.</span><span class="n">issubset</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">maps</span><span class="p">[</span><span class="s2">&quot;Atoms&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">()),</span> \
            <span class="s2">&quot;Undefined atom type found in </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">kw</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">dt</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">distinct_types</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">dt</span><span class="p">:</span>
                <span class="n">mapper</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>

        <span class="k">def</span> <span class="nf">process_data</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
            <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
            <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_valid</span><span class="p">(</span><span class="n">df</span><span class="p">),</span> \
                <span class="s2">&quot;Invalid coefficients with rows varying in length&quot;</span>
            <span class="n">n</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">shape</span>
            <span class="n">df</span><span class="o">.</span><span class="n">columns</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;coeff</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">c</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
            <span class="n">df</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">n</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">df</span>

        <span class="n">all_data</span> <span class="o">=</span> <span class="p">{</span><span class="n">kw</span><span class="p">:</span> <span class="n">process_data</span><span class="p">(</span><span class="n">main_data</span><span class="p">)}</span>
        <span class="k">if</span> <span class="n">class2_data</span><span class="p">:</span>
            <span class="n">all_data</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">process_data</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span>
                             <span class="ow">in</span> <span class="n">class2_data</span><span class="o">.</span><span class="n">items</span><span class="p">()})</span>
        <span class="k">return</span> <span class="n">all_data</span><span class="p">,</span> <span class="p">{</span><span class="n">kw</span><span class="p">[:</span><span class="o">-</span><span class="mi">7</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;s&quot;</span><span class="p">:</span> <span class="n">mapper</span><span class="p">}</span>

<div class="viewcode-block" id="ForceField.to_file"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.ForceField.to_file">[docs]</a>    <span class="k">def</span> <span class="nf">to_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Saves object to a file in YAML format.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;mass_info&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">mass_info</span><span class="p">,</span>
             <span class="s2">&quot;nonbond_coeffs&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">nonbond_coeffs</span><span class="p">,</span>
             <span class="s2">&quot;topo_coeffs&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">topo_coeffs</span><span class="p">}</span>
        <span class="n">yaml</span> <span class="o">=</span> <span class="n">YAML</span><span class="p">(</span><span class="n">typ</span><span class="o">=</span><span class="s2">&quot;safe&quot;</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">yaml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span></div>

<div class="viewcode-block" id="ForceField.from_file"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.ForceField.from_file">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_file</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that reads in a file in YAML format.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename (str): Filename.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">yaml</span> <span class="o">=</span> <span class="n">YAML</span><span class="p">(</span><span class="n">typ</span><span class="o">=</span><span class="s2">&quot;safe&quot;</span><span class="p">)</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">d</span> <span class="o">=</span> <span class="n">yaml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">d</span><span class="p">)</span></div>

<div class="viewcode-block" id="ForceField.from_dict"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.ForceField.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that reads in a dictionary.</span>

<span class="sd">        Args:</span>
<span class="sd">            d (dict): Dictionary to read.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span><span class="p">[</span><span class="s2">&quot;mass_info&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> <span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;mass_info&quot;</span><span class="p">]]</span>
        <span class="k">if</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;topo_coeffs&quot;</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;topo_coeffs&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">v</span><span class="p">:</span>
                    <span class="n">c</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]]</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;mass_info&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;nonbond_coeffs&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;topo_coeffs&quot;</span><span class="p">])</span></div></div>


<div class="viewcode-block" id="CombinedData"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.CombinedData">[docs]</a><span class="k">class</span> <span class="nc">CombinedData</span><span class="p">(</span><span class="n">LammpsData</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Object for a collective set of data for a series of LAMMPS data file.</span>
<span class="sd">    velocities not yet implementd.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">list_of_molecules</span><span class="p">,</span> <span class="n">list_of_names</span><span class="p">,</span> <span class="n">list_of_numbers</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;full&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            list_of_molecules: a list of LammpsData of a single cluster.</span>
<span class="sd">            list_of_names: a list of name for each cluster.</span>
<span class="sd">            list_of_numbers: a list of Integer for counts of each molecule</span>
<span class="sd">                coordinates (pandas.DataFrame): DataFrame with with four</span>
<span class="sd">                columns [&quot;atom&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;] for coordinates of atoms.</span>
<span class="sd">            atom_style (str): Output atom_style. Default to &quot;full&quot;.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">max_xyz</span> <span class="o">=</span> <span class="n">coordinates</span><span class="p">[[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
        <span class="n">min_xyz</span> <span class="o">=</span> <span class="n">coordinates</span><span class="p">[[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">]]</span><span class="o">.</span><span class="n">min</span><span class="p">()</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">box</span> <span class="o">=</span> <span class="n">LammpsBox</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="p">[[</span><span class="n">min_xyz</span> <span class="o">-</span> <span class="mf">0.5</span><span class="p">,</span> <span class="n">max_xyz</span> <span class="o">+</span> <span class="mf">0.5</span><span class="p">]]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atom_style</span> <span class="o">=</span> <span class="n">atom_style</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">list_of_numbers</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">names</span> <span class="o">=</span> <span class="n">list_of_names</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mols</span> <span class="o">=</span> <span class="n">list_of_molecules</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nums</span> <span class="o">=</span> <span class="n">list_of_numbers</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">masses</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">mol</span><span class="o">.</span><span class="n">masses</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">for</span> <span class="n">mol</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mols</span><span class="p">],</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">masses</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">all_ff_kws</span> <span class="o">=</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;ff&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;class2&quot;</span><span class="p">]</span>
        <span class="n">ff_kws</span> <span class="o">=</span> <span class="p">[</span><span class="n">k</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">all_ff_kws</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mols</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">force_field</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">ff_kws</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">([</span><span class="n">mol</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span> <span class="k">for</span> <span class="n">mol</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">mols</span>
                                              <span class="k">if</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">force_field</span><span class="p">],</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()</span>
        <span class="n">mol_count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">type_count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">mol</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mols</span><span class="p">):</span>
            <span class="n">atoms_df</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">atoms_df</span><span class="p">[</span><span class="s1">&#39;molecule-ID&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">mol_count</span>
            <span class="n">atoms_df</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">type_count</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">atoms_df</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                <span class="n">atoms_df</span><span class="p">[</span><span class="s1">&#39;molecule-ID&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="mi">1</span>
            <span class="n">type_count</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mol</span><span class="o">.</span><span class="n">masses</span><span class="p">)</span>
            <span class="n">mol_count</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="p">)</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">coordinates</span><span class="p">),</span> <span class="s1">&#39;Wrong number of coordinates.&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">atoms</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">coordinates</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">velocities</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">mols</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">velocities</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;Velocities not supported&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">topology</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">atom_count</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">count</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;Bonds&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;Angles&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;Dihedrals&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;Impropers&quot;</span><span class="p">:</span> <span class="mi">0</span><span class="p">}</span>
        <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">mol</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mols</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">mol</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">kw</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()</span>
                    <span class="n">topo_df</span> <span class="o">=</span> <span class="n">mol</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                    <span class="n">topo_df</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">count</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span>
                    <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">topo_df</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
                        <span class="n">topo_df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">+=</span> <span class="n">atom_count</span>
                    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]):</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">topo_df</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
                        <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">topo_df</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
                            <span class="n">topo_df</span><span class="p">[</span><span class="n">col</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mol</span><span class="o">.</span><span class="n">atoms</span><span class="p">)</span>
                    <span class="n">count</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mol</span><span class="o">.</span><span class="n">force_field</span><span class="p">[</span><span class="n">kw</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot; Coeffs&quot;</span><span class="p">])</span>
            <span class="n">atom_count</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">mol</span><span class="o">.</span><span class="n">atoms</span><span class="p">)</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="k">for</span> <span class="n">kw</span> <span class="ow">in</span> <span class="n">SECTION_KEYWORDS</span><span class="p">[</span><span class="s2">&quot;topology&quot;</span><span class="p">]:</span>
            <span class="k">if</span> <span class="n">kw</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">topology</span><span class="p">[</span><span class="n">kw</span><span class="p">]</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>

<div class="viewcode-block" id="CombinedData.parse_xyz"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.CombinedData.parse_xyz">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">parse_xyz</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        load xyz file generated from packmol (for those who find it hard to install openbabel)</span>

<span class="sd">        Returns:</span>
<span class="sd">            pandas.DataFrame</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
            <span class="n">lines</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>

        <span class="n">sio</span> <span class="o">=</span> <span class="n">StringIO</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">:]))</span>  <span class="c1"># skip the 2nd line</span>
        <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="n">sio</span><span class="p">,</span> <span class="n">header</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">comment</span><span class="o">=</span><span class="s2">&quot;#&quot;</span><span class="p">,</span> <span class="n">delim_whitespace</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">names</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;atom&#39;</span><span class="p">,</span> <span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">])</span>
        <span class="n">df</span><span class="o">.</span><span class="n">index</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="n">df</span></div>

<div class="viewcode-block" id="CombinedData.from_files"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.CombinedData.from_files">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_files</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">coordinate_file</span><span class="p">,</span> <span class="n">list_of_numbers</span><span class="p">,</span> <span class="o">*</span><span class="n">filenames</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that parse a series of data file.</span>

<span class="sd">        Args:</span>
<span class="sd">            coordinate_file (str): The filename of xyz coordinates.</span>
<span class="sd">            list_of_numbers (list): A list of numbers specifying counts for each</span>
<span class="sd">                clusters parsed from files.</span>
<span class="sd">            filenames (str): A series of filenames in string format.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">names</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mols</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">styles</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">coordinates</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">parse_xyz</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">coordinate_file</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">filenames</span><span class="p">)):</span>
            <span class="n">exec</span><span class="p">(</span><span class="s2">&quot;cluster</span><span class="si">%d</span><span class="s2"> = LammpsData.from_file(filenames[i])&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
            <span class="n">names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;cluster</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span>
            <span class="n">mols</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">eval</span><span class="p">(</span><span class="s2">&quot;cluster</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)))</span>
            <span class="n">styles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">eval</span><span class="p">(</span><span class="s2">&quot;cluster</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">atom_style</span><span class="p">)</span>
        <span class="n">style</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">styles</span><span class="p">)</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">style</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;Files have different atom styles.&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="o">.</span><span class="n">from_lammpsdata</span><span class="p">(</span><span class="n">mols</span><span class="p">,</span> <span class="n">names</span><span class="p">,</span> <span class="n">list_of_numbers</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">,</span> <span class="n">style</span><span class="o">.</span><span class="n">pop</span><span class="p">())</span></div>

<div class="viewcode-block" id="CombinedData.from_lammpsdata"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.CombinedData.from_lammpsdata">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_lammpsdata</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">mols</span><span class="p">,</span> <span class="n">names</span><span class="p">,</span> <span class="n">list_of_numbers</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor that can infer atom_style.</span>
<span class="sd">        The input LammpsData objects are used non-destructively.</span>

<span class="sd">        Args:</span>
<span class="sd">            mols: a list of LammpsData of a single cluster.</span>
<span class="sd">            names: a list of name for each cluster.</span>
<span class="sd">            list_of_numbers: a list of Integer for counts of each molecule</span>
<span class="sd">                coordinates (pandas.DataFrame): DataFrame with with four</span>
<span class="sd">                columns [&quot;atom&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;] for coordinates of atoms.</span>
<span class="sd">            atom_style (str): Output atom_style. Default to &quot;full&quot;.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">styles</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">mol</span> <span class="ow">in</span> <span class="n">mols</span><span class="p">:</span>
            <span class="n">styles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">mol</span><span class="o">.</span><span class="n">atom_style</span><span class="p">)</span>
        <span class="n">style</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">styles</span><span class="p">)</span>
        <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">style</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;Data have different atom_style.&quot;</span>
        <span class="n">style_return</span> <span class="o">=</span> <span class="n">style</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">atom_style</span><span class="p">:</span>
            <span class="k">assert</span> <span class="n">atom_style</span> <span class="o">==</span> <span class="n">style_return</span><span class="p">,</span> <span class="s2">&quot;Data have different atom_style as specified.&quot;</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">mols</span><span class="p">,</span> <span class="n">names</span><span class="p">,</span> <span class="n">list_of_numbers</span><span class="p">,</span> <span class="n">coordinates</span><span class="p">,</span> <span class="n">style_return</span><span class="p">)</span></div>

<div class="viewcode-block" id="CombinedData.get_string"><a class="viewcode-back" href="../../../../pymatgen.io.lammps.data.html#pymatgen.io.lammps.data.CombinedData.get_string">[docs]</a>    <span class="k">def</span> <span class="nf">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">velocity</span><span class="o">=</span><span class="mi">8</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mi">4</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the string representation of CombinedData, essentially</span>
<span class="sd">        the string to be written to a file. Combination info is included.</span>

<span class="sd">        Args:</span>
<span class="sd">            distance (int): No. of significant figures to output for</span>
<span class="sd">                box settings (bounds and tilt) and atomic coordinates.</span>
<span class="sd">                Default to 6.</span>
<span class="sd">            velocity (int): No. of significant figures to output for</span>
<span class="sd">                velocities. Default to 8.</span>
<span class="sd">            charge (int): No. of significant figures to output for</span>
<span class="sd">                charges. Default to 3.</span>

<span class="sd">        Returns:</span>
<span class="sd">            String representation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">LammpsData</span><span class="o">.</span><span class="n">get_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">distance</span><span class="p">,</span> <span class="n">velocity</span><span class="p">,</span> <span class="n">charge</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
        <span class="n">info</span> <span class="o">=</span> <span class="s1">&#39;# &#39;</span> <span class="o">+</span> <span class="s1">&#39; + &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">b</span> <span class="k">for</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nums</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">names</span><span class="p">))</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">info</span><span class="p">)</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span></div></div>


<span class="nd">@deprecated</span><span class="p">(</span><span class="n">LammpsData</span><span class="o">.</span><span class="n">from_structure</span><span class="p">,</span>
            <span class="s2">&quot;structure_2_lmpdata has been deprecated &quot;</span>
            <span class="s2">&quot;in favor of LammpsData.from_structure&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">structure_2_lmpdata</span><span class="p">(</span><span class="n">structure</span><span class="p">,</span> <span class="n">ff_elements</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">atom_style</span><span class="o">=</span><span class="s2">&quot;charge&quot;</span><span class="p">,</span>
                        <span class="n">is_sort</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Converts a structure to a LammpsData object with no force field</span>
<span class="sd">    parameters and topologies.</span>

<span class="sd">    Args:</span>
<span class="sd">        structure (Structure): Input structure.</span>
<span class="sd">        ff_elements ([str]): List of strings of elements that must be</span>
<span class="sd">            present due to force field settings but not necessarily in</span>
<span class="sd">            the structure. Default to None.</span>
<span class="sd">        atom_style (str): Choose between &quot;atomic&quot; (neutral) and</span>
<span class="sd">            &quot;charge&quot; (charged). Default to &quot;charge&quot;.</span>
<span class="sd">        is_sort (bool): whether to sort the structure sites</span>
<span class="sd">    Returns:</span>
<span class="sd">        LammpsData</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">is_sort</span><span class="p">:</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">get_sorted_structure</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">s</span> <span class="o">=</span> <span class="n">structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>

    <span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">abc</span>
    <span class="n">m</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span>
    <span class="n">xhi</span> <span class="o">=</span> <span class="n">a</span>
    <span class="n">xy</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">xhi</span><span class="p">)</span>
    <span class="n">yhi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">b</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">xy</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
    <span class="n">xz</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/</span> <span class="n">xhi</span><span class="p">)</span>
    <span class="n">yz</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">-</span> <span class="n">xy</span> <span class="o">*</span> <span class="n">xz</span><span class="p">)</span> <span class="o">/</span> <span class="n">yhi</span>
    <span class="n">zhi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">c</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">xz</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">-</span> <span class="n">yz</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
    <span class="n">box_bounds</span> <span class="o">=</span> <span class="p">[[</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">xhi</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">yhi</span><span class="p">],</span> <span class="p">[</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">zhi</span><span class="p">]]</span>
    <span class="n">box_tilt</span> <span class="o">=</span> <span class="p">[</span><span class="n">xy</span><span class="p">,</span> <span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">]</span>
    <span class="n">box_tilt</span> <span class="o">=</span> <span class="kc">None</span> <span class="k">if</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">box_tilt</span><span class="p">)</span> <span class="k">else</span> <span class="n">box_tilt</span>
    <span class="n">box</span> <span class="o">=</span> <span class="n">LammpsBox</span><span class="p">(</span><span class="n">box_bounds</span><span class="p">,</span> <span class="n">box_tilt</span><span class="p">)</span>
    <span class="n">new_latt</span> <span class="o">=</span> <span class="n">Lattice</span><span class="p">([[</span><span class="n">xhi</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="n">xy</span><span class="p">,</span> <span class="n">yhi</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="n">xz</span><span class="p">,</span> <span class="n">yz</span><span class="p">,</span> <span class="n">zhi</span><span class="p">]])</span>
    <span class="n">s</span><span class="o">.</span><span class="n">lattice</span> <span class="o">=</span> <span class="n">new_latt</span>

    <span class="n">symbols</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">symbol_set</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">ff_elements</span><span class="p">:</span>
        <span class="n">symbols</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">ff_elements</span><span class="p">)</span>
    <span class="n">elements</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">Element</span><span class="p">(</span><span class="n">el</span><span class="p">)</span> <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="nb">set</span><span class="p">(</span><span class="n">symbols</span><span class="p">))</span>
    <span class="n">mass_info</span> <span class="o">=</span> <span class="p">[</span><span class="nb">tuple</span><span class="p">([</span><span class="n">i</span><span class="o">.</span><span class="n">symbol</span><span class="p">]</span> <span class="o">*</span> <span class="mi">2</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">elements</span><span class="p">]</span>
    <span class="n">ff</span> <span class="o">=</span> <span class="n">ForceField</span><span class="p">(</span><span class="n">mass_info</span><span class="p">)</span>
    <span class="n">topo</span> <span class="o">=</span> <span class="n">Topology</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">LammpsData</span><span class="o">.</span><span class="n">from_ff_and_topologies</span><span class="p">(</span><span class="n">box</span><span class="o">=</span><span class="n">box</span><span class="p">,</span> <span class="n">ff</span><span class="o">=</span><span class="n">ff</span><span class="p">,</span> <span class="n">topologies</span><span class="o">=</span><span class="p">[</span><span class="n">topo</span><span class="p">],</span>
                                             <span class="n">atom_style</span><span class="o">=</span><span class="n">atom_style</span><span class="p">)</span>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.io.lammps.data</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>